import { createStore } from "vuex";

interface MyStore {
  maxCount: number;
  loading: false;
}

export default createStore<MyStore>({
  state: {
    maxCount: 0,
    loading: false,
  },
  getters: {
    getMaxCount: (state) => {
      return state.maxCount;
    },
    // getDoubleCount: (state, getter) => {
    //   return state.maxCount + getter.getMaxCount();
    // },
    // getParam: (state) => {
    //   return (param: string) => state.maxCount + param;
    // },
  },
  mutations: {
    setLoading: (state, status) => {
      state.loading = status;
    },
    fetchDataCount: (state, newData) => {
      const { maxCount } = state;
      // debugger;
      state.maxCount = maxCount + newData;
      // return {
      //   maxCount: maxCount + newData,
      // };
    },
  },
  actions: {
    fetchMaxCount: ({ state, commit }, params) => {
      const { data: newData } = params;
      // console.log(params, "params ");
      commit("setLoading", true);
      setTimeout(() => {
        commit("fetchDataCount", newData);
        commit("setLoading", false);
      }, 1000);

      return newData;
    },
  },
  modules: {},
});
